package com.ruoyi.mobile.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.mobile.domain.ShOrderEntity;
import com.ruoyi.system.api.resp.DictResp;
import com.ruoyi.system.api.resp.ShOrderResp;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 订单信息Mapper接口
 */
@Mapper
@DS("master")
public interface IShOrderMapper extends BaseMapper<ShOrderEntity> {
    @Select("select order_no as orderNo,address_id as addressId,status,sum(num) as num,sum(pay_amount) as payAmount,sum(amount) as amount, "+
            "GROUP_CONCAT(distinct product_id) as productIds from sh_order "+
            "where create_by=#{createBy} and product_id in (SELECT id FROM sh_product WHERE product_type<=80 and app_id=#{appId}) "+
            "group by order_no,address_id,status order by create_time desc")
    public List<ShOrderResp> getOrderPayList1(@Param("createBy")Long createBy, @Param("appId")String appId);

    @Select("select order_no as orderNo,address_id as addressId,status,sum(num) as num,sum(pay_amount) as payAmount,sum(amount) as amount, "+
            "GROUP_CONCAT(distinct product_id) as productIds from sh_order "+
            "where create_by=#{createBy} and product_id in (SELECT id FROM sh_product WHERE product_type>90 and app_id=#{appId}) "+
            "group by order_no,address_id,status order by create_time desc")
    public List<ShOrderResp> getOrderPayList2(@Param("createBy")Long createBy, @Param("appId")String appId);

    @Select("select order_no as orderNo,address_id as addressId,status,sum(num) as num,sum(pay_amount) as payAmount,sum(amount) as amount, "+
            "GROUP_CONCAT(distinct product_id) as productIds from sh_order "+
            "where create_by=#{createBy} and product_id in (SELECT id FROM sh_product WHERE product_type>80 and product_type<=90 and app_id=#{appId}) "+
            "group by order_no,address_id,status order by create_time desc")
    public List<ShOrderResp> getOrderPayList3(@Param("createBy")Long createBy, @Param("appId")String appId);

    @Select("select order_no as orderNo,address_id as addressId,status,sum(num) as num,sum(pay_amount) as payAmount,sum(amount) as amount, "+
            "GROUP_CONCAT(distinct product_id) as productIds from sh_order "+
            "where create_by=#{createBy} and product_id in (SELECT id FROM sh_product WHERE product_type=#{productType} and app_id=#{appId}) "+
            "group by order_no,address_id,status order by create_time desc")
    public List<ShOrderResp> getOrderPayList(@Param("createBy")Long createBy, @Param("productType")Integer productType, @Param("appId")String appId);

    int insertBatch(List<ShOrderEntity> list);

    @Update("update sh_order set status=#{status} where order_no=#{orderNo}")
    int updateOrderStatusByOrderNo(@Param("status")String status,@Param("orderNo")String orderNo);
    @Update("update material_order set status=#{status} where order_no=#{orderNo}")
    int updateOrderStatusByOrderNoM(@Param("status")String status,@Param("orderNo")String orderNo);
    @Update("update materialjk_order set status=#{status} where order_no=#{orderNo}")
    int updateOrderStatusByOrderNoV(@Param("status")String status,@Param("orderNo")String orderNo);
}